package com.yellowpage.tool;

import java.text.DecimalFormat;
import java.util.*;

/**
 * Created by Sun on 12/9/2015.
 */

//给出了内容的拼接，将表数据转换为字符串
public class ContentGet
{
    //给出了返回结果字符串的函数
    public static String contentget(List<Map> resultList,LinkedHashMap namemap)
    {
        String contentresult = "";
        Set<String> keyset = namemap.keySet();

        //放置每一个字段的值
        for (int i = 0, len = resultList.size(); i < len; i++)
        {

            //写入到log中
            Map result = resultList.get(i);


            for(Iterator iter = keyset.iterator(); iter.hasNext();)
            {
                Object key = iter.next();
                String nametemp = String.valueOf(namemap.get(key));
                String value = result.get(key) != null ? result.get(key).toString() : "";
                String name = null;
                try {
                //将vlaue转换为通用格式
                    name = new String(nametemp.getBytes("UTF-8"),"UTF-8");
                }
                catch (Exception e)
                {
                    System.out.print(e);
                }


                //拼接字符串，用以返回
                //当字符串不适合转换成以万单位的时候

                if(!name.equals("日期") && Double.parseDouble(value) > 10000)
                {
                    //保留两位小数
                    DecimalFormat df = new DecimalFormat("######0.00");
                    value = df.format(Double.parseDouble(value) / 10000) + "万 ";
                }
                contentresult = contentresult + name + ": " + value + "\n";

            }
        }


        return  contentresult;

    }
}
